Skip to content

feat(content): add a versioned payload codec#142

Open
marcus-pousette wants to merge 1 commit into
mainfrom
image-payload-experiment
Open

feat(content): add a versioned payload codec#142
marcus-pousette wants to merge 1 commit into
mainfrom
image-payload-experiment

Conversation

@marcus-pousette

@marcus-pousette marcus-pousette commented May 6, 2026

Copy link
Copy Markdown
Collaborator

What this does

Adds @treecrdt/content, a small application-layer codec for storing typed content in TreeCRDT's Uint8Array payloads.

  • Plain text uses raw UTF-8 as the canonical representation.
  • Images use one versioned binary envelope containing validated MIME metadata, an exact declared byte length, and the original image bytes.
  • Recognized but malformed or unsupported envelopes fail closed instead of being interpreted as text.

TreeCRDT core stays media-agnostic. This package is an optional protocol above the byte payload API.

Fast paths

  • Text encoding is a direct UTF-8 encode with no envelope, migration, or alternate decoder.
  • Unframed bytes decode directly as text.
  • Image decoding returns a bounded view of the original bytes instead of copying the image body.

The raw text representation is deliberate, not a backward-compatibility layer: framing text as well would add bytes and another envelope path without improving type discrimination.

Safety

  • Parses correctly from non-zero-offset Uint8Array views.
  • Validates envelope version, metadata length, declared image length, JSON metadata shape, and an explicit image MIME allowlist.
  • Includes a static golden fixture to pin the image wire format.
  • Payload-size policy and object URL lifetime remain application concerns.

Scope

This PR is only the reusable codec: 9 files, +346/-2.

Playground UI, remote-sync presets, benchmarks, and the 1 MB JPEG fixture are intentionally separate.

Validation

  • Codec tests: 6/6
  • Package TypeScript build
  • Package tarball/exports verification

@marcus-pousette marcus-pousette added enhancement New feature or request area:web Browser, WASM, OPFS, workers, and playground runtime area:api Public interfaces, bindings, events, and cross-backend contracts labels Jul 12, 2026
@marcus-pousette
marcus-pousette force-pushed the image-payload-experiment branch from 0515495 to a3384e8 Compare July 12, 2026 14:40
@marcus-pousette marcus-pousette changed the title Experiment with image payloads in playground feat(content): add a versioned payload codec Jul 12, 2026
@marcus-pousette marcus-pousette removed the area:web Browser, WASM, OPFS, workers, and playground runtime label Jul 12, 2026
@marcus-pousette
marcus-pousette marked this pull request as ready for review July 12, 2026 14:41
@marcus-pousette
marcus-pousette force-pushed the image-payload-experiment branch from a3384e8 to 68b7160 Compare July 13, 2026 15:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:api Public interfaces, bindings, events, and cross-backend contracts enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant